<?php

// appel du header
require_once('./include/header.php');

if ( $_user->isLogged() ) {

    $template->set_filenames(array(
            'body' => 'disponibilitees.tpl'
    ));

    $template->assign_var('TITLE', 'Mutualisation Projet');
    $template->assign_var('CSS_PAGE', './style/css/disponibilitees.css');


    if ( isset($_GET['action']) ) {


    }

    if ( isset($_GET['display']) ) {


    }

    if ( isset($_GET['step']) ) {
        if ( $_GET['step'] == 1 ) {

            $template->assign_block_vars("step_1", null);

            if ( $droits['multiple_centre'] || $droits['dieu'] ) {

                $template->assign_block_vars('step_1.multiple_centre', null);

                $structure = new Structure();
                $structure->charger_arrayCentreID_structure();
                $structure->charger_arrayCentre_structure();

                if ( isset($_POST['POST']) )
                    $first_centre_id = $_POST['POST'];
                else
                    $first_centre_id = null;

                if ( $droits_parametres['multiple_centre'] == 'all' || $droits['dieu'] ) {

                    for ( $i = 0 ; $i < count($structure->array_centre_id) ; $i++ ) {
                        $centre = unserialize($structure->array_centre[$structure->array_centre_id[$i]]);
                        $template->assign_block_vars('step_1.multiple_centre.centre', array(
                                'id' => $centre->centre_id,
                                'nom' => $centre->centre_nom
                        ));

                        if ( $first_centre_id == null && $i == 0 ) $first_centre_id = $centre->centre_id;
                    }

                } else {

                    $listes_centres = explode(',', $droits_parametres['multiple_centre']);

                    for ( $i = 0 ; $i < count($listes_centres) ; $i++ ) {
                        $centre = unserialize($structure->array_centre[$listes_centres[$i]]);
                        $template->assign_block_vars('step_1.multiple_centre.centre', array(
                                'id' => $centre->centre_id,
                                'nom' => $centre->centre_nom
                        ));

                        if ( $first_centre_id == null && $i == 0 ) $first_centre_id = $centre->centre_id;
                    }


                }

                $_SESSION['first_centre_id'] = $first_centre_id;

            }

            if ( $droits['multiple_pompier'] || $droits['multiple_centre'] || $droits['dieu'] ) {

                if ( $droits['multiple_pompier'] ) $_SESSION['first_centre_id'] = $droits_parametres['multiple_pompier'];

                $template->assign_block_vars('step_1.multiple_pompier', null);

            }

        } else {
            if ( $_GET['step'] == 2 ) {

                $template->assign_block_vars("step_2", array(
                        'dateJour' => date('j/m/Y', $_POST['dateValeur']/1000)
                ));

                for ( $i=0 ; $i < count($_metier->array_typeGarde_id) ; $i++ ) {
                    $typeGarde = unserialize($_metier->array_typeGarde[$_metier->array_typeGarde_id[$i]]);
                    $template->assign_block_vars('step_2.type_garde', array(
                            'nom' => $typeGarde->typeGarde_nom
                    ));
                }

                if ( $_POST['matricules'] == 'null' ) {

                    for ( $i = 0 ; $i < count($_individus->array_pompier_id) ; $i++ ) {

                        $pompier = unserialize($_individus->array_pompier[$_individus->array_pompier_id[$i]]);
                        $personne = unserialize($_individus->array_personne[$pompier->personne_id]);

                        $grade = unserialize($_metier->array_grade[$pompier->grade_id]);

                        if( $pompier->personne_id == $_user->personne_id )
                            $template->assign_block_vars('step_2.pompier', array(
                                    'grade_nom_prenom_matricule' => $grade->grade_abbr . ' ' . $personne->personne_nom . ' ' . $personne->personne_prenom . ' (' . $pompier->pompier_matricule . ')',
                                    'matricule' => $pompier->pompier_matricule
                            ));

                    }

                    /*
                    $template->assign_block_vars('step_2.pompier', array(
                            'matricule' => 
                    ));
                    */

                } else {
                    $matricules = explode(',', $_POST['matricules']);

                    for ( $i = 0 ; $i < count($matricules) ; $i++ ) {

                        $pompier = unserialize($_individus->array_pompier[$_individus->getPompierID_with_Matricule( $matricules[$i] )]);
                        $personne = unserialize($_individus->array_personne[$pompier->personne_id]);

                        $grade = unserialize($_metier->array_grade[$pompier->grade_id]);

                        $template->assign_block_vars('step_2.pompier', array(
                                'grade_nom_prenom_matricule' => $grade->grade_abbr . ' ' . $personne->personne_nom . ' ' . $personne->personne_prenom . ' (' . $pompier->pompier_matricule . ')',
                                'matricule' => $pompier->pompier_matricule
                        ));
                    }

                }
            }
        }
    }

    $template->pparse('header');
    $template->pparse('body');
    $template->pparse('footer');

} else {
    header("Location: ./401.php");
}

// appel du footer
require_once('./include/footer.php');

?>
